<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%--<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>--%>
<%--<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>--%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${tabTitle}</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">

    <%--        <div id="pageInTab" class="pageInTab">--%>
    <form id="prj_no_sign_date_info">
        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_100" id="searchPrjStsCdId">
                <div class="label">机构名称</div>
                <div class="field">
                    <span>${prjNoSignDateInfoDTO.insName}</span>
                </div>
            </div>
            <div class="fieldBox col_100 no-sign-date-box">
                <div class="label">已有不可签署日期</div>
                <div class="field">
                    <c:forEach items="${list}" var="item" varStatus="status">
                        <div style="display: block;">
                            <c:out value="${item}"/>
                            <a class="sq-button-hasicon delete-button" href="javascript:;">
                                    删除
                            </a>
                        </div>
                    </c:forEach>
                </div>
            </div>
            <div class="fieldBox col_33 ">
                <div class="label">新增不可签署日期</div>
                <div class="field">
                    <input name="newnoSignDate" id="newnoSignDate" type="text" class="ui-datepicker" value="" validate="{required:true}" >
                </div>
            </div>
        </div>
        <input type="hidden" value="${prjNoSignDateInfoDTO.id}" id="id">
        <input type="hidden" value="${list}" id="dateList">
        <div class="btnsBox" style="text-align: center;">
            <span id="saveBtn"  class="sq-button sq-button-round">保存</span>
            <span id="cancelBtn" class="sq-button sq-button-round">取消</span>
        </div>
    </form>

</div>

<script type="text/javascript">
    $(function(){
        $("#newnoSignDate").ligerDateEditor({
            // showTime: true,
            width:"180",
            // format:"yyyy-MM-dd hh:mm:ss"
            onChangeDate:function(value){
                var html="";
                newList.push(value);
                newList.sort(function (a, b) {
                    return new Date(a).getTime() - new Date(b).getTime()
                });
                newList=Array.from(new Set(newList))
                for(var i=0,len=newList.length;i<len;i++){
                    html += ` <div style="display: block;">`+
                        newList[i]+
                                `<a class="sq-button-hasicon delete-button" href="javascript:;">
                                        删除
                                </a>
                            </div>`;
                }
                $(".no-sign-date-box .field").html(html);
                console.log(newList)
            }
        });

        var prj_no_sign_date_info = $('#prj_no_sign_date_info').ligerForm({
            validate : true
        });
        SET_popupIframeHeight();

    });
    var newList=$("#dateList").val()?$("#dateList").val().replace(/\s*/g,"").replace('[','').replace(']','').split(','):[];
    //关闭
    $('#cancelBtn').click(function(){
        frameElement.dialog.close();
    });
    //保存
    $('#saveBtn').click(function(){
        var id = $("#id").val();
        $.ajax({
            url:"<%=path%>/institution/nosigndate/updatenosigndate.do",
            data:JSON.stringify({
                noSignDate:newList,
                id:id,
                insertFlag:false
            }),
            dataType:"json",
            type:"post",
            contentType:"application/json; charset=utf-8",
            async:false,
            cache:false,
            success: function (msg) {
                debugger;
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    parent.$("#searchBtn").click();
                    frameElement.dialog.close();
                }
            },
            error:function () {
                UIUtils.alertError("保存失败");
            }
        });

    });

    //删除
    $(".no-sign-date-box").on("click",".delete-button",function(){

        let ind=$(this).parent().index();

        newList.splice(ind,1)
        $(this).parent().remove()
        // console.log(newList)
    })

</script>

</body>
</html>